const express = require('express')
const router = express.Router();
const md5 = require('blueimp-md5')
const UserModel = require("../models/UserModel")

// 测试接口
router.get("/test", (req, res) => {
    res.send("连接成功")
})
// 登录接口
router.post("/login", (req, res) => {
    const {
        username,
        password
    } = req.body
    UserModel.findOne({
        username,
        password: md5(password)
    }).then(user => {
        if (user) {
            // 超级管理员
            user._doc.role = {
                menus: []
            }
            res.send({
                status: 0,
                data: user
            })


        } else {
            res.send({
                status: 1,
                msg: '用户名或密码错误'
            })
        }
    })
})


module.exports = router